﻿using System;
using System.Collections.Generic;
using System.IO;

class Solution
{
    static void Main(String[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] rank = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; ++i)
        {
            rank[i] = int.Parse(Console.ReadLine());
            a[i] = 1;
        }
        for (int i = 1; i < n; ++i)
        {
            if (rank[i] > rank[i - 1])
                a[i] = a[i - 1] + 1;
        }
        for (int i = n - 2; i >= 0; --i)
        {
            if (rank[i] > rank[i + 1])
                a[i] = Math.Max(a[i], a[i + 1] + 1);
        }
        int total = 0;
        for (int i = 0; i < n; ++i)
            total += a[i];
        Console.WriteLine(total);
    }
}